package com.hk.devp.captcha.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.captcha.botdetect.web.servlet.Captcha;

@Controller
@RequestMapping("/botDetect")
public class BotDetectController {
	/**
	* @author: dragon0574@sina.com
	* @date 2017年7月31日 上午9:41:36 
	* @param response
	* @param request
	* @return 
	* @Description:去往botDetect验证码页面
	 */
	@RequestMapping("/toBotDetectPage")
	public String toBotDetect(HttpServletResponse response,HttpServletRequest request){
		
		return "botDetect";
	}
	
	
	@RequestMapping("/genBotDetectCaptcha")
	public void genBotDetectCaptcha(){
		//CaptchaServlet
		
	}
	
	@RequestMapping("/login")
	public String login(HttpServletRequest request,HttpServletResponse response){
		
		HttpSession session = request.getSession(true);
		String captchaCode = request.getParameter("captchaCode");
		// exampleCaptcha为前端form表单中验证所在div容器的id值
		Captcha captcha = Captcha.load(request, "exampleCaptcha");
		boolean isHuman = captcha.validate(captchaCode);
		//boolean isHuman = captcha.validate(basicExample.getCaptchaCode());

		if (isHuman) {
		  // TODO: Captcha validation passed, perform protected action
		} else {
		  // TODO: Captcha validation failed, show error message
		}
		return "redirect:/botDetect/toBotDetectPage";
	}
	
	
}
